﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    /// <summary>
    /// <FontFamily Value="微软雅黑"/>
    /// </summary>
    public class XFontFamilyConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            string fontName = valueNode.Attributes["Value"].ToUpper();
            return new FontFamily(fontName);
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            FontFamily font = value as FontFamily;
            Metadata.ValueNode valueNode = new Metadata.ValueNode("FontFamily");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", font == null ? string.Empty : font.Source);
            return valueNode;
        }
    }
}
